# -*- coding: UTF-8 -*-

import sys
import os
import copy

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url1 = 'https://www.baidu.com/s?wd=300617'
url2 = 'https://www.baidu.com/s?wd=300207'

path = r'D:\chromedriver_win32\chromedriver.exe'

s = Service(path)

locator = (By.CLASS_NAME, 'price_2jYb9')

def getps(dm):
	opt = webdriver.ChromeOptions()
	opt.headless = True
	opt.add_argument('blink-settings=imagesEnabled=false')
	browser = webdriver.Chrome(options=opt, service=s)
	url = 'https://www.baidu.com/s?wd=' + dm
	browser.get(url)
	WebDriverWait(browser, 10, 0.5).until(EC.presence_of_element_located(locator))
	price = copy.deepcopy(browser.find_element(by=By.CLASS_NAME, value="price_2jYb9").text)
	browser.quit()
	return price

if __name__ == '__main__':
	akzd = getps("300617")
	xwd = getps("300207")
	ktsw = getps("300601")
	gdzq = getps("601788")
	print("akzd:" + akzd)
	print("xwd:" + xwd)
	print("ktsw:" + ktsw)
	print("gdzq:" + gdzq)
	
